package random.fox.p2p.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;
import flow.Flow;
import random.fox.p2p.App;
import random.fox.p2p.Paths;
import random.fox.p2p.R;
import random.fox.p2p.event.ProgressEvent;
import random.fox.p2p.model.RegisterModule;
import random.fox.p2p.presenter.RegisterPresenter;
import random.fox.p2p.view.IRegisterView;

/**
 * Created by wq on 15/3/14.
 */
public class SetPasswordView extends LinearLayout implements IRegisterView {

    @Inject RegisterPresenter presenter;

    @InjectView(R.id.edt_set_password) EditText edtPassword;

    public SetPasswordView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ButterKnife.inject(this);
        ((App) getContext().getApplicationContext()).createScopedGraph(new RegisterModule(this)).inject(this);
    }

    @OnClick(R.id.btn_next) void nextClicked(){
        presenter.setPassword(edtPassword.getText()+"");
    }

    @Override
    public void showProgress() {
        EventBus.getDefault().post(new ProgressEvent(true));
    }

    @Override
    public void hideProgress() {
        EventBus.getDefault().post(new ProgressEvent(false));
    }

    @Override
    public void showCode() {
        //do nothing
    }

    @Override
    public void errorCode() {
        //do nothing
    }

    @Override
    public void errorPhone() {
        //do nothing
    }

    @Override
    public void goToNext() {
        Flow.get(getContext()).set(new Paths.SetInfoPath());
    }

    @Override
    public void showMessage(String message) {
        Toast.makeText(getContext(),message,Toast.LENGTH_SHORT).show();
    }

}
